package com.ml.view;


import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;


/**
 * This Service is Persistent Service. Do some what you want to do here.<br/>
 * <p>
 * Created by Mars on 12/24/15.
 */
public class Service1 extends Service {

    public static final String INTENT_MODE = "INTENT_MODE";
    String data = "";

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        data = intent.getStringExtra(INTENT_MODE);
        Log.e("colin83", "Service1-onStartCommand-- " + data);

        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        //单独启动service也会进AppContext
        //控制无效！可能有时间差
        Log.d("colin83", "Service1-startActivity!!!");

//            Intent mainActivityIntent = new Intent(this, WelcomeActivity.class);  // 要啟動的Activity
//            mainActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//            startActivity(mainActivityIntent);
        //不能发activity定义的消息，需在service里定义
        IntentFilter filter = new IntentFilter();
        filter.setPriority(1000);
        filter.addAction("com.ml.view.startapp");
        BootBroadcastReceiver receiver = new BootBroadcastReceiver();
        registerReceiver(receiver, filter);
        sendBroadcast(new Intent("com.ml.view.startapp"));//app退出后自定义消息就收不到了

    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
